@extends('layouts.default')
@section('css')
    <link rel="stylesheet" href="{{asset('admin-lte/plugins/datatables/dataTables.bootstrap4.css')}}">
    {{--<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">--}}
@stop

@section('content')
<div class="row">
    <div class="col-12">
        <div class="card">
            <div class="card-header">
                <h3 class="card-title">优惠券管理 / <a class="text-primary" href="{{url('admin/coupon/coupon_list')}}">优惠券规则列表</a></h3>
            </div>

            <div class="card-body">
                @include('layouts.message')
                <button class="btn btn-info btn-sm" style="margin-bottom:10px" onclick="location.href='{{url('admin/coupon/create_coupon_form')}}'">添加优惠券</button>
                <table id="example1" class="table table-bordered table-striped">
                    <thead>
                    <tr>
                        <th>操作</th>
                        <th>优惠规则</th>
                        <th>优惠券</th>
                        <th>名称</th>
                        {{--<th>描述</th>--}}
                        <th>总数</th>
                        <th>领取数</th>
                        <th>每人限领</th>
                        <th>开始时间</th>
                        <th>结束时间</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach ($lists as $v)
                    <tr>
                        <td>
                            <button class="btn btn-sm btn-primary" onclick="location.href='{{url('admin/coupon/edit_coupon_form',['coupon_id'=>$v['coupon_id']])}}'">编辑</button>
                            <button data-url="{{url('admin/coupon/delete_coupon',['coupon_id'=>$v['coupon_id']])}}" class="btn btn-sm btn-danger del-goods">删除</button>
                        </td>
                        <td>规则</td>
                        <td>优惠券</td>
                        <td>{{ $v['title'] }}</td>
                        <td>{{ $v['send_num'] == -1 ? '无限制' : $v['send_num']}}</td>
                        <td>{{ $v['get_num'] }}</td>
                        <td>{{ $v['limit_per_get'] == -1 ? '无限制' : $v['limit_per_get']}}</td>
                        <td>{{ date('Y-m-d H:i:s',$v['start_time']) }}</td>
                        <td>{{ date('Y-m-d H:i:s',$v['end_time']) }}</td>
                    </tr>
                    @endforeach
                    </tbody>
                    <tfoot>
                    <tr>
                        <td colspan="9"></td>
                    </tr>
                    </tfoot>
                </table>
            </div>
        </div>
    </div>
</div>

@stop





@section('script')
<script src="{{asset('admin-lte/plugins/datatables/jquery.dataTables.js')}}"></script>
<script src="{{asset('admin-lte/plugins/datatables/dataTables.bootstrap4.js')}}"></script>
{{--layer插件--}}
<script src='{{asset("admin-lte/plugins/layer-v3.1.1/layer.js")}}' type="text/javascript"></script>
<script>
    $(function () {
        $("#example1").DataTable({
            "language"  : {
                url :'https://cdn.datatables.net/plug-ins/1.10.19/i18n/Chinese.json'
            },
            //启用或者禁用某一列的排序功能
            "columnDefs": [
                { "orderable": false, "targets": 0 }
            ],

            buttons: [
                {
                    text: 'Alert',
                    action: function ( e, dt, node, config ) {
                        alert( 'Activated!' );
                        this.disable(); // disable button
                    }
                }
            ]
        });

    });

    $('.del-goods').click(function(e){
        layer.confirm('确认要删除该优惠吗？',function(){
            location.href = $(e.target).data('url');
        })
    })


</script>
@stop



